package tlias.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tlias.dto.ClazzCountDTO;
import tlias.dto.JobStatisticsDTO;
import tlias.dto.StatisticsItemDTO;
import tlias.mapper.ReportMapper;
import tlias.pojo.*;
import tlias.service.ReportService;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    private final ReportMapper reportMapper;

    public ReportServiceImpl(ReportMapper reportMapper) {
        this.reportMapper = reportMapper;
    }

    @Override
    public List<StatisticsItemDTO> getEmpGenderStatistics() {
        return reportMapper.countEmpGender();
    }

    @Override
    public JobStatisticsDTO getEmpJobStatistics() {
        List<StatisticsItemDTO> jobCounts = reportMapper.countEmpJob();
        
        JobStatisticsDTO result = new JobStatisticsDTO();
        List<String> jobList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (StatisticsItemDTO item : jobCounts) {
            jobList.add(item.getName());
            dataList.add(item.getValue());
        }
        result.setJobList(jobList);
        result.setDataList(dataList);
        return result;
    }

    @Override
    public List<StatisticsItemDTO> getStudentDegreeStatistics() {
        return reportMapper.countStudentDegree();
    }

    @Override
    public ClazzCountDTO getStudentCountStatistics() {
        List<StatisticsItemDTO> clazzCounts = reportMapper.countStudentByClazz();
        
        ClazzCountDTO result = new ClazzCountDTO();
        result.setClazzList(new ArrayList<>());
        result.setDataList(new ArrayList<>());
        for (StatisticsItemDTO item : clazzCounts) {
            result.getClazzList().add(item.getName());
            result.getDataList().add(item.getValue());
        }
        return result;
    }
}